import logging
import os
import utils.myconfig as config

# log_file_path = config.get_config('LOG', 'log_output_path')

log_file_path = os.path.join(os.getcwd(), config.get_config('LOG', 'log_output_path'))

def getLogger(logname):
    # 创建一个logger
    logger = logging.getLogger(logname)
    logger.setLevel(logging.INFO)
    # 写入日志文件handler
    file_handler = logging.FileHandler(log_file_path, encoding='utf-8')
    file_handler.setLevel(logging.INFO)
    # 输出到控制台handler
    console_handler = logging.StreamHandler()
    console_handler.setLevel(logging.INFO)

    # 定义输出格式
    formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(name)s: %(message)s-(%(pathname)s:%(lineno)d)')
    file_handler.setFormatter(formatter)
    console_handler.setFormatter(formatter)

    # 给logger添加handler
    logger.addHandler(file_handler)
    logger.addHandler(console_handler)

    return logger
